package com.coding.controller;

import com.coding.base.pojo.BaseModel;
import com.coding.base.pojo.PageQueryModel;
import com.coding.service.CollectService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @auther wangchenghao
 * @date 2020/7/28
 **/
@Controller
@ResponseBody
@RequestMapping("collect")
public class CollectController {
    @Autowired
    private CollectService collectService;

    @ApiOperation("检查帖子是否收藏")
    @RequestMapping(value = "/checkPostCollect", method = {RequestMethod.GET})
    public BaseModel checkPostCollect(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                      @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        collectService.checkCollect(user_id, source_id, "post", model);
        return model;
    }

    @ApiOperation("检查诗词是否收藏")
    @RequestMapping(value = "/checkPoemCollect", method = {RequestMethod.GET})
    public BaseModel checkPoemCollect(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                      @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        collectService.checkCollect(user_id, source_id, "poem", model);
        return model;
    }

    @ApiOperation("检查景点是否收藏")
    @RequestMapping(value = "/checkMainPlaceCollect", method = {RequestMethod.GET})
    public BaseModel checkMainPlaceCollect(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                           @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        collectService.checkCollect(user_id, source_id, "mainplace", model);
        return model;
    }

    @ApiOperation("新增收藏帖子")
    @RequestMapping(value = "/addPost", method = {RequestMethod.PUT})
    public BaseModel addpost(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                             @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        collectService.addnewcollectpost(user_id, source_id, model);
        return model;
    }

    @ApiOperation("分页查询收藏帖子")
    @RequestMapping(value = "/getPost", method = {RequestMethod.GET})
    public BaseModel getpost(@ApiParam("user_id") @RequestParam(value = "user_id", required = true) Integer user_id,
                             @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        collectService.getcollectpost(user_id, pageQueryModel, model);
        return model;
    }

    @ApiOperation("新增收藏景点")
    @RequestMapping(value = "/addPlace", method = {RequestMethod.PUT})
    public BaseModel addplace(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                              @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        collectService.addnewcollectplace(user_id, source_id, model);
        return model;
    }

    @ApiOperation("分页查询收藏景点")
    @RequestMapping(value = "/getPlace", method = {RequestMethod.GET})
    public BaseModel getplace(@ApiParam("user_id") @RequestParam(value = "user_id", required = true) Integer user_id,
                              @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        collectService.getcollectplace(user_id, pageQueryModel, model);
        return model;
    }

    @ApiOperation("新增收藏诗词")
    @RequestMapping(value = "/addPoem", method = {RequestMethod.PUT})
    public BaseModel addPoem(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                             @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        collectService.addNewCollectPoem(user_id, source_id, model);
        return model;
    }

    @ApiOperation("分页查询收藏诗词")
    @RequestMapping(value = "/getPoem", method = {RequestMethod.GET})
    public BaseModel getPoem(@ApiParam("user_id") @RequestParam(value = "user_id", required = true) Integer user_id,
                             @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        collectService.getCollectPoem(user_id, pageQueryModel, model);
        return model;
    }

    @ApiOperation("查询用户所有收藏")
    @RequestMapping(value = "/getAllCollect", method = {RequestMethod.GET})
    public BaseModel getAllCollect(@ApiParam("user_id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                   @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        collectService.getUserCollect(user_id, pageQueryModel, model);
        return model;
    }

    @ApiOperation("取消帖子收藏")
    @RequestMapping(value = "/deletePostCollect", method = {RequestMethod.DELETE})
    public BaseModel deletePostCollect(@ApiParam("user_id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                       @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id) throws Exception {
        BaseModel model = new BaseModel();
        collectService.deleteCollect(user_id, source_id, "post", model);
        return model;
    }

    @ApiOperation("取消诗词收藏")
    @RequestMapping(value = "/deletePoemCollect", method = {RequestMethod.DELETE})
    public BaseModel deletePoemCollect(@ApiParam("user_id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                       @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id) throws Exception {
        BaseModel model = new BaseModel();
        collectService.deleteCollect(user_id, source_id, "poem", model);
        return model;
    }

    @ApiOperation("取消主要景点收藏")
    @RequestMapping(value = "/deleteMainPlaceCollect", method = {RequestMethod.DELETE})
    public BaseModel deleteMainPlaceCollect(@ApiParam("user_id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                            @ApiParam("资源id") @RequestParam(value = "source_id", required = true) Integer source_id) throws Exception {
        BaseModel model = new BaseModel();
        collectService.deleteCollect(user_id, source_id, "mainplace", model);
        return model;
    }

}
